package com.part2.action.function;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ajaxanywhere.AAUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.part2.action.common.Config;
import com.part2.action.common.form.CustomActionForm;
import com.part2.action.common.form.ValueObject;
import com.part2.beans.News;
import com.part2.business.function.BigClassService;
import com.part2.business.function.JobService;
import com.part2.business.function.MarkService;
import com.part2.business.function.NewsService;
import com.part2.business.function.ProductsService;
import com.part2.business.function.SmallclassService;
import com.part2.business.function.UsersService;

public class TestAction extends DispatchAction{
	private final Log logger = LogFactory.getLog(getClass());
	private BigClassService bigClassService;
	private JobService jobService;
	private MarkService markService;
	private NewsService newsService;
	private ProductsService productsService;
	private SmallclassService smallClassService;
	private UsersService userService;

	public void setBigClassService(BigClassService bigClassService) {
		this.bigClassService = bigClassService;
	}

	public void setJobService(JobService jobService) {
		this.jobService = jobService;
	}

	public void setMarkService(MarkService markService) {
		this.markService = markService;
	}



	public void setProductsService(ProductsService productsService) {
		this.productsService = productsService;
	}

	public void setSmallClassService(SmallclassService smallClassService) {
		this.smallClassService = smallClassService;
	}

	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}

	public void setUserService(UsersService userService) {
		this.userService = userService;
	}
	
	public ActionForward index(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		ActionMessages errors = new ActionMessages();
		ValueObject cVo = ((CustomActionForm) form).getVoa()
				.getValue("test");
		String companyName = cVo.getField("companyName");
		Config.writeProperties("companyName", companyName);
		logger.info(Config.readValue("companyName"));
		List<News> newsList = newsService.findNews();
		
		if(AAUtils.isAjaxRequest(request)){
			AAUtils.addZonesToRefreh(request, "tt,t1");
			request.setAttribute("a", companyName);
			request.setAttribute("list", newsList.toArray());
			System.out.println("++++++++++++++++++++++++");
		}
		request.setAttribute("list", newsList);
		return mapping.findForward("su");
	}
}
